import {
  SEARCH_FOCUS,
  ADD_HEADER_LIST,
  SEARCH_BLUR,
  MOUSE_ENTER,
  MOUSE_LEAVE,
  PAGE_CHANGE
} from './actionCreators'
import { fromJS } from 'immutable'

const defaultState = fromJS({
  searchFocused: false,
  mouseIn: false,
  list: [],
  page: 1,
  totalPage: 1
})

export default (state = defaultState, action) => {
  switch (action.type) {
    case SEARCH_FOCUS: {
      return state.set('searchFocused', true)
    }
    case ADD_HEADER_LIST: {
      // return state.set('list', action.list).set('totalPage', action.totalPage)
      return state.merge({
        list: action.list,
        totalPage: action.totalPage
      })
    }
    case SEARCH_BLUR: {
      return state.set('searchFocused', false)
    }
    case MOUSE_ENTER: {
      return state.set('mouseIn', true)
    }
    case MOUSE_LEAVE: {
      return state.set('mouseIn', false)
    }
    case PAGE_CHANGE: {
      return state.set('page', action.page)
    }
    default:
      return state
  }
}
